//
//  TWHorizontalScrollCardCell.swift
//  EyepetizerImitative
//
//  Created by 田伟 on 2017/3/24.
//  Copyright © 2017年 个人. All rights reserved.
//

import UIKit
import SDWebImage
import SDCycleScrollView

protocol HorizontalScrollCardCellDelegate : NSObjectProtocol {
    func cycleScrollViewDidSelectItemAt(selectedItem : TWBannerModel)
}

class TWHorizontalScrollCardCell: UITableViewCell , SDCycleScrollViewDelegate{

    @IBOutlet weak var ImageScrollView: SDCycleScrollView!
    
    // MARK:- 自定义属性
    var horizontalScrollCardModel : TWHorizontalScrollCard?{
        didSet {
            guard let horizontalScrollCardModel = horizontalScrollCardModel else {
                return
            }
            // 取出里面的数组
            var imageUrl : [String] = [String]()
            let itemList = horizontalScrollCardModel.itemList_tw_HS
            itemInfo = itemList
            for item in itemList {
                let imageStr = item.image
                imageUrl.append(imageStr!)
            }
            ImageScrollView.imageURLStringsGroup = imageUrl
            ImageScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter
            ImageScrollView.autoScrollTimeInterval = 2
            ImageScrollView.titleLabelBackgroundColor = UIColor.clear
            ImageScrollView.clearCache()
        }
    }
    
    var itemInfo : [TWBannerModel]?
    var horizontalScrollCardCellDelegate : HorizontalScrollCardCellDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        ImageScrollView.delegate = self
        ImageScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter
        ImageScrollView.autoScrollTimeInterval = 2
        ImageScrollView.titleLabelBackgroundColor = UIColor.clear
        ImageScrollView.clearCache()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }
    
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
        horizontalScrollCardCellDelegate?.cycleScrollViewDidSelectItemAt(selectedItem: (itemInfo?[index])!)
    }
}
